import java.util.Stack;

public class ReverseStack{
	public static int getAndRemoveLastElement(Stack<Integer> stack){
		log("get-start: ",stack);
		int result = stack.pop();
		if( stack.empty() ){
			return result;
		} else {
			int last = getAndRemoveLastElement(stack);
			stack.push(result);
			log("get: ",stack);
			return last;
		}
	}

	public static void reverse(Stack<Integer> stack){
		log("reverse-start:",stack);
		if( stack.empty() ) {
			return ;
		}
		int i = getAndRemoveLastElement(stack);
		reverse(stack);
		stack.push(i);
		log(" reverse: ",stack);
	}

	public static void log(String method,Stack<Integer> stack){
		System.out.println(method +" > "+ stack.toString() );
	}

	public static void main(String[] args){
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(1);
		stack.push(2);
		stack.push(3);

		ReverseStack.reverse(stack);
		ReverseStack.log("result: ",stack);
	}
}

